---@class GT.ui.control.slider : GT.ui
---@field u table<RoleID,GT.ui.control.slider> 玩家独立数据驱动
---@field binding GT.ui.control.slider
GT.ui.control.slider = class(GT.ui, false)


---@class ui_data_slider : ui_data
---@field percent float 滑动条的进度
ui_data_slider = {
    percent = nil,
}

--- 创建滑块
---@param data ui_data_slider
---@return GT.ui.control.slider
function GT.ui.control.slider:ctor(data)
    data.class=GT.ui.control.slider
    if data.uid ~= nil then
        super(self, data)
    else
        data.u_type = GT.ui.type.slider
        self.percent = data.percent

        --创建控件
        super(self, data)

        if self.percent then
            self:set_slider_value(self.percent)
        end
    end

    self:slider_watch()
    return self
end

--监听绑定
---@return GT.ui.control.slider
function GT.ui.control.slider:slider_watch()
    ---@type bind_data[]
    local data = {
        {
            key = "percent",
            func = function(val, old)
                self.percent = val
                self:set_slider_value(self.percent)
            end
        }
    }
    self.bind:add(data)
    return self
end

--设置滑动条的进度
---@param  percent float 滑动条的进度
function GT.ui.control.slider:set_slider_value(percent)
    game_api.set_slider_cur_percent(self.player.player , self, Fix32(percent))
    return self
end

--获取滑动条当前值
function GT.ui.control.slider:get_slider_current_value()
    return game_api.get_slider_cur_percent(self.uid)
end
